package com.mooc.lib_sofa.ui.sofa

import com.mooc.lib_common.model.FeedDissEntity
import com.mooc.lib_common.model.FeedLikeEntity
import com.mooc.lib_common.model.FeedShareEntity
import com.mooc.lib_common.model.HomeFeedEntity
import com.mooc.lib_network.entity.BaseRepository
import com.mooc.lib_network.entity.NetResult
import com.mooc.lib_network.entity.RetrofitSingle
import com.mooc.lib_sofa.ApiService

/**
 * 沙发网络请求
 * */
class SofaRepo : BaseRepository(){

    //下拉刷新
    suspend fun requestRefresh(feedId : Int,feedType : String,count : Int,userId : Int):NetResult<HomeFeedEntity>{
        return requestCall ( call = {
            requestFeed(feedId,feedType,count,userId) }
        )
    }

    //上拉加载
    suspend fun requestLoad(feedId : Int,feedType : String,count : Int,userId : Int):NetResult<HomeFeedEntity>{
        return requestCall ( call = {
            requestFeed(feedId,feedType,count,userId) }
        )
    }

    //model层请求数据获取
    suspend fun requestFeed(feedId : Int,feedType : String,count : Int,userId : Int):NetResult<HomeFeedEntity>{
        return handlerResponse(
            RetrofitSingle.instance().getRetrofit().create(ApiService::class.java)
                .requestHomeList(feedId,feedType,count,userId)
        )
    }

    //喜欢
    suspend fun requestLike(itemId : Long,userId : Int):NetResult<FeedLikeEntity>{
        return handlerResponse(
            RetrofitSingle.instance().getRetrofit().create(ApiService::class.java)
                .requestLike(itemId,userId)
        )
    }
    //踩
    suspend fun requestDiss(itemId : Long,userId : Int):NetResult<FeedDissEntity>{
        return handlerResponse(
            RetrofitSingle.instance().getRetrofit().create(ApiService::class.java)
                .requestDiss(itemId,userId)
        )
    }
    //分享数量
    suspend fun requestShare(itemId : Long):NetResult<FeedShareEntity>{
        return handlerResponse(
            RetrofitSingle.instance().getRetrofit().create(ApiService::class.java)
                .requestShare(itemId)
        )
    }

    suspend fun like(itemId : Long,userId : Int):NetResult<FeedLikeEntity>{
        return  requestCall (
            call = {requestLike(itemId,userId)
            } )
    }

    suspend fun diss(itemId : Long,userId : Int):NetResult<FeedDissEntity>{
        return  requestCall (
            call = {requestDiss(itemId,userId)
            } )
    }

    suspend fun share(itemId : Long):NetResult<FeedShareEntity>{
        return  requestCall (
            call = {requestShare(itemId)
            } )
    }

}